package com.yiqi.lottery.feature.mine.view;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.suozhang.framework.entity.bo.UserInfoBo;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.framework.BaseActivity;
import com.suozhang.framework.utils.T;
import com.suozhang.framework.widget.PowerfulEditText;
import com.yiqi.lottery.R;
import com.yiqi.lottery.entity.bo.TokenBo;
import com.yiqi.lottery.feature.mine.contract.MineContract;
import com.yiqi.lottery.feature.mine.dependencies.mine.DaggerMineComponent;
import com.yiqi.lottery.feature.mine.dependencies.mine.MinePresenterModule;

import javax.inject.Inject;

public class EditNickActivity extends BaseActivity implements MineContract.View {

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.edt_user_edit_name)
    PowerfulEditText mEdtUserEditName;
    @Inject
    MineContract.Presenter mPresenter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_edit_nick;
    }

    @Override
    protected void initInjector() {
        DaggerMineComponent.builder().minePresenterModule(new MinePresenterModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {

        initToolBar(mToolbar, "", true, true);
    }

    @Override
    protected void initData() {
        if (AM.user().isLogin()) {
            mEdtUserEditName.setText(AM.user().getLoginResultCache().getUsername());
        }
    }


    @Override
    public void showUserInfoSuccess(UserInfoBo userInfoBo) {
        T.showShort("修改成功！");
        if (userInfoBo!=null){
            AM.user().saveLoginResultCache(userInfoBo);
            finish();
        }

    }

    @Override
    public void showAuthSuccess(String msg) {

    }

    @Override
    public void showSendCodeSuccess(String code) {


    }

    @Override
    public void showEditPwdSuccess(String msg) {

    }

    @Override
    public void showSendCodeError(String error) {

    }

    @Override
    public void showError(String error) {
        T.showShort(error);
    }

    @Override
    public void showQiniuTokenSuccess(TokenBo data) {

    }

    @Override
    public void showUploadHashSuccess(String hash) {

    }


    @OnClick(R.id.btn_user_nickname_save)
    public void onViewClicked() {
        if (AM.user().isLogin()){
            mPresenter.editNick(AM.user().getLoginResultCache().getUser_id(),mEdtUserEditName.getText().toString());
        }
    }
}
